package com.dime.physical.service.impl;

import com.dime.physical.domain.*;
import com.dime.physical.domain.dto.*;
import com.dime.physical.mapper.*;
import com.dime.physical.service.IDimeReportService;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteDictService;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysDictData;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
public class DimeReportServiceImpl implements IDimeReportService {

    @Autowired
    private DimePhysicalflowMapper dimePhysicalflowMapper;

    @Autowired
    private DimePhysicalcombsMapper dimePhysicalcombsMapper;

    @Autowired
    private DimePhysicalitemsMapper dimePhysicalitemsMapper;

    @Autowired
    private DimePhysicaladviceMapper dimePhysicaladviceMapper;

    @Autowired
    private DimePhysicalharmsMapper dimePhysicalharmsMapper;

    @Autowired
    private DimePhysicalpictureMapper dimePhysicalpictureMapper;

    @Autowired
    private DimeMaincheckhealthadviceMapper dimeMaincheckhealthadviceMapper;

    @Autowired
    private DimePhysicalconsionMapper dimePhysicalconsionMapper;

    @Autowired
    private DimeMaincheckconclusionMapper dimeMaincheckconclusionMapper;

    @Autowired
    private DimeInquiryitemsMapper dimeInquiryitemsMapper;

    @Autowired
    private DimeInquirychronicoccupationalhistoryMapper dimeInquirychronicoccupationalhistoryMapper;

    @Autowired
    private DimeInquirycurrentdiseasesMapper dimeInquirycurrentdiseasesMapper;

    @Autowired
    private DimeInquirydiseaseMapper dimeInquirydiseaseMapper;

    @Autowired
    private DimeInquiryoccupationsMapper dimeInquiryoccupationsMapper;

    @Autowired
    private DimeInquiryradiationotherMapper dimeInquiryradiationotherMapper;

    @Autowired
    private DimeInquiryradiationoccupationsMapper dimeInquiryradiationoccupationsMapper;

    @Autowired
    private DimeInquirysymptomMapper dimeInquirysymptomMapper;

    @Autowired
    private DimeInquirysignMapper dimeInquirysignMapper;

    @Autowired
    private RemoteDictService remoteDictService;

    @Autowired
    private RemoteUserService remoteUserService;




    @Autowired
    private DimeMaincheckharmconclusionMapper dimeMaincheckharmconclusionMapper;


    @Autowired
    private DimeMaincheckharmrecheckcombMapper dimeMaincheckharmrecheckcombMapper;

    @Autowired
    private DimePhysicalregisterMapper dimePhysicalregisterMapper;

    @Autowired
    private DimeMaincheckharmcontraindicationMapper dimeMaincheckharmcontraindicationMapper;

    @Autowired
    private DimeMaincheckharmoccupationaldiseaeMapper dimeMaincheckharmoccupationaldiseaeMapper;


    @Override
    public PhysicalReportDto getPhysicalPersonReport(DimePhysicalregister dimePhysicalregister) {

        PhysicalReportDto reportDto = MappingPhysical(dimePhysicalregister);

        List<DimePhysicalflow> dimePhysicalflowList = dimePhysicalflowMapper.selectDimePhysiacaflowByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimePhysicalflows(dimePhysicalflowList);

        List<DimePhysicalcombs> dimePhysicalcombsList = dimePhysicalcombsMapper.selectDimePhysicalcombsByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimePhysicalcombs(dimePhysicalcombsList);

        List<DimePhysicalitems> dimePhysicalitemsList = dimePhysicalitemsMapper.selectDimePhysicalitemsByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimePhysicalitems(dimePhysicalitemsList);

        List<DimePhysicaladvice> dimePhysicaladvicesList = dimePhysicaladviceMapper.selectDimePhysicaladviceByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimePhysicaladvices(dimePhysicaladvicesList);

        List<DimePhysicalharms> dimePhysicalharmsList = dimePhysicalharmsMapper.selectDimePhysicalharmsByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimePhysicalharms(dimePhysicalharmsList);

        List<DimePhysicalpicture> dimePhysicalpictureList = dimePhysicalpictureMapper.selectDimePhysicalpictureByphysicalRegisterId(dimePhysicalregister.getId());
        reportDto.setDimePhysicalpictures(dimePhysicalpictureList);


        List<DimeMaincheckhealthadvice> dimeMaincheckhealthadviceList = dimeMaincheckhealthadviceMapper.selectDimeMaincheckhealthadviceByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimeMaincheckhealthadvices(dimeMaincheckhealthadviceList);

        List<DimePhysicalconsion> dimePhysicalconsionList = dimePhysicalconsionMapper.selectDimePhysicalconsionByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimePhysicalconsions(dimePhysicalconsionList);


        DimeMaincheckconclusion dimeMaincheckconclusion = dimeMaincheckconclusionMapper.selectDimeMaincheckconclusionByPhysicalId(dimePhysicalregister.getId());
        reportDto.setDimeMaincheckconclusion(dimeMaincheckconclusion);

        DimeInquiryitems dimeInquiryitems = dimeInquiryitemsMapper.selectDimeInquiryitemsByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquiryitems(dimeInquiryitems);

        List<DimeInquirychronicoccupationalhistory> inquirychronicoccupationalhistoryList = dimeInquirychronicoccupationalhistoryMapper.selectDimeInquirychronicoccupationalhistoryByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquirychronicoccupationalhistory(inquirychronicoccupationalhistoryList);


        List<DimeInquirycurrentdiseases> dimeInquirycurrentdiseasesList = dimeInquirycurrentdiseasesMapper.selectDimeInquirycurrentdiseasesByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquirycurrentdiseases(dimeInquirycurrentdiseasesList);

        List<DimeInquirydisease> dimeInquirydiseaseList = dimeInquirydiseaseMapper.selectDimeInquirydiseaseByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquirydisease(dimeInquirydiseaseList);

        List<DimeInquiryoccupations> dimeInquiryoccupationsList = dimeInquiryoccupationsMapper.selectDimeInquiryoccupationsByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquiryoccupations(dimeInquiryoccupationsList);

        DimeInquiryradiationother inquiryradiationother = dimeInquiryradiationotherMapper.selectDimeInquiryradiationotherByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquiryradiationother(inquiryradiationother);

        List<DimeInquiryradiationoccupations> dimeInquiryradiationoccupationsList = dimeInquiryradiationoccupationsMapper.selectDimeInquiryradiationoccupationsByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquiryradiationoccupations(dimeInquiryradiationoccupationsList);

        List<DimeInquirysymptom> dimeInquirysymptomList = dimeInquirysymptomMapper.selectDimeInquirysymptomByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquirysymptom(dimeInquirysymptomList);

        DimeInquirysign dimeInquirysign = dimeInquirysignMapper.selectDimeInquirysignByPhysicalId(dimePhysicalregister.getId());
        reportDto.setInquirysign(dimeInquirysign);


        return reportDto;
    }


    @Override
    public PersonReportDto getPhysicalReport(DimePhysicalregister dimePhysicalregister) {

        PersonReportDto personReportDto = new PersonReportDto();

        List<ReportBasicInfo> dimePhysicalregisters = new ArrayList<>();

        ReportBasicInfo reportBasicInfo = ReportMappingPhysical(dimePhysicalregister);



        //主检签名
        R<LoginUser> MainchenckUserR = remoteUserService.getUserInfo(dimePhysicalregister.getMainCheckDoctor(), SecurityConstants.INNER);
        if (MainchenckUserR.getCode() != R.FAIL) {
            LoginUser loginUser = MainchenckUserR.getData();
            if (loginUser != null && loginUser.getSysUser() != null)
                reportBasicInfo.setMainCheckDoctorSign(loginUser.getSysUser().getImageUrl());
        }
        //在岗状态
        SysDictData searchdicdata=new SysDictData();
        searchdicdata.setDictType("dime_physical_work");
        searchdicdata.setDictValue(reportBasicInfo.getWorkStatus());

        R<SysDictData> Rdic = remoteDictService.getDictTypeName(searchdicdata);
        if (Rdic.getCode() != R.FAIL) {
            SysDictData dictData = Rdic.getData();
            reportBasicInfo.setWorkStatusName(dictData.getDictLabel());
        }
        dimePhysicalregisters.add(reportBasicInfo);
        personReportDto.setV_print_basicinfo(dimePhysicalregisters);

        //项目
        List<DimePhysicalitems> dimePhysicalitemsList = dimePhysicalitemsMapper.selectDimePhysicalitemsByPhysicalId(dimePhysicalregister.getId());

        //电测听图片
        List<DimePhysicalpicture> dimePhysicalpictureList = dimePhysicalpictureMapper.selectDimePhysicalpictureByphysicalRegisterId(dimePhysicalregister.getId());


        if (dimePhysicalitemsList != null) {

            //实验室项目
            List<DimePhysicalitems> labitems = dimePhysicalitemsList.stream().filter(x -> Objects.equals(x.getItemType(), "03")).collect(Collectors.toList());

            List<ReportLabDto> reportLabDtos = new ArrayList<>();
            for (DimePhysicalitems dimePhysicalitem : labitems) {
                ReportLabDto reportLabDto = new ReportLabDto();
                reportLabDto.setCheckCode(dimePhysicalregister.getCheckCode());
                reportLabDto.setPhysicalRegisterId(dimePhysicalregister.getId());
                reportLabDto.setItemName(dimePhysicalitem.getItemName());
                reportLabDto.setJudgeType(dimePhysicalitem.getJudgeType());
                reportLabDto.setResult(dimePhysicalitem.getResult());
                reportLabDto.setUnit(dimePhysicalitem.getUnit());
                reportLabDto.setValStandard(dimePhysicalitem.getValStandard());
                reportLabDto.setValmax(dimePhysicalitem.getValmax());
                reportLabDto.setValmin(dimePhysicalitem.getValmin());
                reportLabDto.setGroupName(dimePhysicalitem.getGroupName());
                reportLabDto.setCheckDate(dimePhysicalitem.getResultInputDate());
                reportLabDto.setDoctorName(dimePhysicalitem.getDoctorName());
                reportLabDto.setDoctorSign(dimePhysicalitem.getDoctorUrl());
                reportLabDto.setRecheckdoctorName(dimePhysicalitem.getRecheckdoctorName());
                reportLabDto.setRecheckdoctorSign(dimePhysicalitem.getRecheckdoctorUrl());
                reportLabDto.setSn(dimePhysicalitem.getSn());
                reportLabDtos.add(reportLabDto);
            }
            personReportDto.setV_print_lab(reportLabDtos);


            //电测听
            List<DimePhysicalitems> BSRitems = dimePhysicalitemsList.stream().filter(x -> Objects.equals(x.getItemType(), "06")).collect(Collectors.toList());

            List<ReportBSRItemsDto> reportBSRItemsDtos = new ArrayList<>();
            for (DimePhysicalitems dimePhysicalitem : BSRitems) {


                ReportBSRItemsDto reportBSRItemsDto = new ReportBSRItemsDto();
                reportBSRItemsDto.setCheckCode(dimePhysicalregister.getCheckCode());
                reportBSRItemsDto.setPhysicalRegisterId(dimePhysicalregister.getId());
                reportBSRItemsDto.setItemName(dimePhysicalitem.getItemName());
                reportBSRItemsDto.setJudgeType(dimePhysicalitem.getJudgeType());
                reportBSRItemsDto.setResult(dimePhysicalitem.getResult());
                reportBSRItemsDto.setUnit(dimePhysicalitem.getUnit());
                reportBSRItemsDto.setValStandard(dimePhysicalitem.getValStandard());
                reportBSRItemsDto.setValmax(dimePhysicalitem.getValmax());
                reportBSRItemsDto.setValmin(dimePhysicalitem.getValmin());
                reportBSRItemsDto.setGroupName(dimePhysicalitem.getGroupName());
                reportBSRItemsDto.setCheckDate(dimePhysicalitem.getResultInputDate());
                reportBSRItemsDto.setDoctorName(dimePhysicalitem.getDoctorName());
                reportBSRItemsDto.setDoctorSign(dimePhysicalitem.getDoctorUrl());
                reportBSRItemsDto.setSn(dimePhysicalitem.getSn());
                R<LoginUser> loginUserR = remoteUserService.getUserInfo(dimePhysicalitem.getCreateBy(), SecurityConstants.INNER);
                if (loginUserR.getCode() != R.FAIL) {
                    LoginUser loginUser = loginUserR.getData();
                    if (loginUser != null && loginUser.getSysUser() != null)
                        reportBSRItemsDto.setDoctorSign(loginUser.getSysUser().getImageUrl());
                }

                reportBSRItemsDtos.add(reportBSRItemsDto);
            }
            personReportDto.setV_print_bera(reportBSRItemsDtos);

            // 电测听图
            if (dimePhysicalpictureList != null) {
                List<DimePhysicalpicture> dimePhysicalpictures = dimePhysicalpictureList.stream().filter(x -> Objects.equals(x.getGroupName(), "电测听")).collect(Collectors.toList());
                List<ReportBSRItemPicDto> reportBSRItemPicDtosleft = new ArrayList<>();
                List<ReportBSRItemPicDto> reportBSRItemPicDtosright = new ArrayList<>();

                for (DimePhysicalpicture dimePhysicalpicture : dimePhysicalpictures) {
                    ReportBSRItemPicDto reportBSRItemPicDto = new ReportBSRItemPicDto();
                    reportBSRItemPicDto.setCheckCode(dimePhysicalregister.getCheckCode());
                    reportBSRItemPicDto.setPhysicalRegisterId(dimePhysicalregister.getId());
                    reportBSRItemPicDto.setFilepath(dimePhysicalpicture.getFilepath());
                    if (dimePhysicalpicture.getFilename().contains("left")) {
                        reportBSRItemPicDtosleft.add(reportBSRItemPicDto);
                    } else if (dimePhysicalpicture.getFilename().contains("right")) {
                        reportBSRItemPicDtosright.add(reportBSRItemPicDto);
                    }

                }
                personReportDto.setV_print_bera_left(reportBSRItemPicDtosleft);
                personReportDto.setV_print_bera_right(reportBSRItemPicDtosright);

                List<DimePhysicalpicture> Physicalpictures=dimePhysicalpictureList.stream().filter(x -> !Objects.equals(x.getGroupName(), "电测听")).collect(Collectors.toList());
                personReportDto.setV_print_images(Physicalpictures);


            }


            // 一般检查
            List<DimePhysicalitems> Physiqueitems = dimePhysicalitemsList.stream().filter(x -> Objects.equals(x.getItemType(), "01")).collect(Collectors.toList());
            List<ReportPhysiqueDto> reportPhysiqueDtos = new ArrayList<>();
            for (DimePhysicalitems dimePhysicalitem : Physiqueitems) {
                ReportPhysiqueDto reportPhysiqueDto = new ReportPhysiqueDto();
                reportPhysiqueDto.setCheckCode(dimePhysicalregister.getCheckCode());
                reportPhysiqueDto.setPhysicalRegisterId(dimePhysicalregister.getId());
                reportPhysiqueDto.setItemName(dimePhysicalitem.getItemName());
                reportPhysiqueDto.setJudgeType(dimePhysicalitem.getJudgeType());
                reportPhysiqueDto.setResult(dimePhysicalitem.getResult());
                reportPhysiqueDto.setUnit(dimePhysicalitem.getUnit());
                reportPhysiqueDto.setValStandard(dimePhysicalitem.getValStandard());
                reportPhysiqueDto.setValmax(dimePhysicalitem.getValmax());
                reportPhysiqueDto.setValmin(dimePhysicalitem.getValmin());
                reportPhysiqueDto.setGroupName(dimePhysicalitem.getGroupName());
                reportPhysiqueDto.setCheckDate(dimePhysicalitem.getResultInputDate());
                reportPhysiqueDto.setDoctorName(dimePhysicalitem.getDoctorName());
                reportPhysiqueDto.setDoctorSign(dimePhysicalitem.getDoctorUrl());
                reportPhysiqueDto.setSn(dimePhysicalitem.getSn());
                if(dimePhysicalitem.getDoctorUrl()==null|| Objects.equals(dimePhysicalitem.getDoctorUrl(), ""))
                {
                    R<LoginUser> loginUserR = remoteUserService.getUserInfo(dimePhysicalitem.getCreateBy(), SecurityConstants.INNER);
                    if (loginUserR.getCode() != R.FAIL) {
                        LoginUser loginUser = loginUserR.getData();
                        if (loginUser != null && loginUser.getSysUser() != null)
                            reportPhysiqueDto.setDoctorSign(loginUser.getSysUser().getImageUrl());
                    }

                }

                reportPhysiqueDtos.add(reportPhysiqueDto);
            }

            personReportDto.setV_print_physique(reportPhysiqueDtos);

            //器械
            List<DimePhysicalitems> Instrumentitems = dimePhysicalitemsList.stream().filter(x -> Objects.equals(x.getItemType(), "02")).collect(Collectors.toList());
            if (Instrumentitems.size() > 0) {
                List<ReportInstrumentDto> reportInstrumentDtos = new ArrayList<>();
                for (DimePhysicalitems dimePhysicalitem : Instrumentitems) {
                    ReportInstrumentDto reportInstrumentDto = new ReportInstrumentDto();
                    reportInstrumentDto.setCheckCode(dimePhysicalregister.getCheckCode());
                    reportInstrumentDto.setPhysicalRegisterId(dimePhysicalregister.getId());
                    reportInstrumentDto.setItemName(dimePhysicalitem.getItemName());
                    reportInstrumentDto.setJudgeType(dimePhysicalitem.getJudgeType());
                    reportInstrumentDto.setResult(dimePhysicalitem.getResult());
                    reportInstrumentDto.setUnit(dimePhysicalitem.getUnit());
                    reportInstrumentDto.setValStandard(dimePhysicalitem.getValStandard());
                    reportInstrumentDto.setValmax(dimePhysicalitem.getValmax());
                    reportInstrumentDto.setValmin(dimePhysicalitem.getValmin());
                    reportInstrumentDto.setGroupName(dimePhysicalitem.getGroupName());
                    reportInstrumentDto.setCheckDate(dimePhysicalitem.getResultInputDate());
                    reportInstrumentDto.setDoctorSign(dimePhysicalitem.getDoctorUrl());
                    reportInstrumentDto.setSn(dimePhysicalitem.getSn());
                }
                personReportDto.setV_print_instrument(reportInstrumentDtos);
            }

        }
        //问诊内容
        List<DimeInquirydisease> dimeInquirydiseaseList = dimeInquirydiseaseMapper.selectDimeInquirydiseaseByPhysicalId(dimePhysicalregister.getId());

        List<ReportInquirydiseaseDto> reportInquirydiseaseDtos = new ArrayList<>();
        if (dimeInquirydiseaseList != null && dimeInquirydiseaseList.size() > 0) {

            for (DimeInquirydisease dimeInquirydisease : dimeInquirydiseaseList) {
                ReportInquirydiseaseDto reportDiseaseDto = new ReportInquirydiseaseDto();

                reportDiseaseDto.setCheckCode(dimePhysicalregister.getCheckCode());
                reportDiseaseDto.setDoctorName(dimeInquirydisease.getDoctorName());
                reportDiseaseDto.setDiseaseName(dimeInquirydisease.getDiseaseName());
                reportDiseaseDto.setDiagnoseDate(dimeInquirydisease.getDiagnoseDate());
                reportDiseaseDto.setDiagnosis(dimeInquirydisease.getDiagnosis());
                reportDiseaseDto.setTreatment(dimeInquirydisease.getTreatment());
                reportDiseaseDto.setOccupational(dimeInquirydisease.getOccupational());
                reportDiseaseDto.setPhysicalRegisterId(dimePhysicalregister.getId());
                reportDiseaseDto.setRemark(dimeInquirydisease.getRemark());

                reportInquirydiseaseDtos.add(reportDiseaseDto);
            }
        }
        personReportDto.setV_print_inquirydisease(reportInquirydiseaseDtos);


        DimeInquiryitems dimeInquiryitems = dimeInquiryitemsMapper.selectDimeInquiryitemsByPhysicalId(dimePhysicalregister.getId());
        List<ReportInquiryitemsDto> reportInquiryitemsDtos = new ArrayList<>();
        if (dimeInquiryitems != null) {

            ReportInquiryitemsDto reportInquiryitemsDto = new ReportInquiryitemsDto();
            reportInquiryitemsDto.setCheckCode(dimePhysicalregister.getCheckCode());
            reportInquiryitemsDto.setSmoke(dimeInquiryitems.getSmoke());
            reportInquiryitemsDto.setSmokequantity(dimeInquiryitems.getSmokequantity().toString());
            reportInquiryitemsDto.setSmokeyears(dimeInquiryitems.getSmokeyears().toString());
            reportInquiryitemsDto.setDrink(dimeInquiryitems.getDrink());
            reportInquiryitemsDto.setDrinkyears(dimeInquiryitems.getDrinkyears().toString());
            reportInquiryitemsDto.setDrinkquantity(dimeInquiryitems.getDrinkquantity().toString());
            reportInquiryitemsDto.setMenstrbegin(dimeInquiryitems.getMenstrbegin() == null ? "" :dimeInquiryitems.getMenstrbegin().toString());
            reportInquiryitemsDto.setMenstrlen(dimeInquiryitems.getMenstrlen() == null ? "" :dimeInquiryitems.getMenstrlen().toString());
            reportInquiryitemsDto.setMenstrcycle(dimeInquiryitems.getMenstrcycle() == null ? "" :dimeInquiryitems.getMenstrcycle().toString());
            reportInquiryitemsDto.setMenstrend(dimeInquiryitems.getMenstrend() == null ? "" :dimeInquiryitems.getMenstrend().toString());
            reportInquiryitemsDto.setChildrencount(dimeInquiryitems.getChildrencount() == null ? "" :dimeInquiryitems.getChildrencount().toString());
            reportInquiryitemsDto.setAbortiontimes(dimeInquiryitems.getAbortiontimes() == null ? "" :dimeInquiryitems.getAbortiontimes().toString());
            reportInquiryitemsDto.setPrematuretimes(dimeInquiryitems.getPrematuretimes() == null ? "" :dimeInquiryitems.getPrematuretimes().toString());
            reportInquiryitemsDto.setReproducedied(dimeInquiryitems.getReproducedied() == null ? "" :dimeInquiryitems.getReproducedied().toString());
            reportInquiryitemsDto.setGraviditycount(dimeInquiryitems.getGraviditycount() == null ? "" :dimeInquiryitems.getGraviditycount().toString());
            reportInquiryitemsDto.setLivebrithcount(dimeInquiryitems.getLivebrithcount() == null ? "" :dimeInquiryitems.getLivebrithcount().toString());
            reportInquiryitemsDto.setTeratomacount(dimeInquiryitems.getTeratomacount() == null ? "" : dimeInquiryitems.getTeratomacount().toString());
            reportInquiryitemsDto.setMostcount(dimeInquiryitems.getMostcount() == null ? "" :dimeInquiryitems.getMostcount().toString());
            reportInquiryitemsDto.setEccyesiscount(dimeInquiryitems.getEccyesiscount() == null ? "" :dimeInquiryitems.getEccyesiscount().toString());
            reportInquiryitemsDto.setInfertility(dimeInquiryitems.getInfertility());
            reportInquiryitemsDto.setBoys(dimeInquiryitems.getBoys() == null ? "" :dimeInquiryitems.getBoys().toString());
            reportInquiryitemsDto.setBoybrithdays(dimeInquiryitems.getBoybrithdays());
            reportInquiryitemsDto.setChildhealth(dimeInquiryitems.getChildhealth());
            reportInquiryitemsDto.setOther(dimeInquiryitems.getOther());
            reportInquiryitemsDto.setFamily(dimeInquiryitems.getFamily());
            reportInquiryitemsDto.setPersonal(dimeInquiryitems.getPersonal());
            reportInquiryitemsDto.setRemark(dimeInquiryitems.getRemark());
            reportInquiryitemsDto.setPhysicalRegisterId(dimePhysicalregister.getId());
            reportInquiryitemsDtos.add(reportInquiryitemsDto);
        }
        personReportDto.setV_print_inquiryitems(reportInquiryitemsDtos);

        List<DimeInquiryoccupations> dimeInquiryoccupationsList = dimeInquiryoccupationsMapper.selectDimeInquiryoccupationsByPhysicalId(dimePhysicalregister.getId());

        List<ReportInquiryoccupationsDto> reportInquiryoccupationsDtos = new ArrayList<>();
        if (dimeInquiryoccupationsList != null && dimeInquiryoccupationsList.size() > 0) {


            for (DimeInquiryoccupations dimeInquiryoccupation : dimeInquiryoccupationsList) {

                ReportInquiryoccupationsDto reportInquiryoccupationsDto = new ReportInquiryoccupationsDto();
                reportInquiryoccupationsDto.setCheckCode(dimePhysicalregister.getCheckCode());
                reportInquiryoccupationsDto.setDatefromto(dimeInquiryoccupation.getDatefromto());
                reportInquiryoccupationsDto.setCompany(dimeInquiryoccupation.getCompany());
                reportInquiryoccupationsDto.setWorkshop(dimeInquiryoccupation.getWorkshop());
                reportInquiryoccupationsDto.setOccupationtype(dimeInquiryoccupation.getOccupationtype());
                reportInquiryoccupationsDto.setHarmfactor(dimeInquiryoccupation.getHarmfactor());
                reportInquiryoccupationsDto.setProtectmeasure(dimeInquiryoccupation.getProtectmeasure());
                if (dimeInquiryitems != null) {
                    reportInquiryoccupationsDto.setRemark(dimeInquiryitems.getRemark());
                }

                reportInquiryoccupationsDtos.add(reportInquiryoccupationsDto);
            }
        }
        personReportDto.setV_print_inquiryoccupations(reportInquiryoccupationsDtos);


        List<DimeInquiryradiationoccupations> dimeInquiryradiationoccupationsList = dimeInquiryradiationoccupationsMapper.selectDimeInquiryradiationoccupationsByPhysicalId(dimePhysicalregister.getId());

        List<ReportInquiryradiationoccupationsDto> reportInquiryradiationoccupationsDtos = new ArrayList<>();

        if (dimeInquiryradiationoccupationsList != null && dimeInquiryradiationoccupationsList.size() > 0) {

            for (DimeInquiryradiationoccupations dimeInquiryradiationoccupation : dimeInquiryradiationoccupationsList) {
                ReportInquiryradiationoccupationsDto reportInquiryradiationoccupationsDto = new ReportInquiryradiationoccupationsDto();

                reportInquiryradiationoccupationsDto.setCheckCode(dimePhysicalregister.getCheckCode());
                reportInquiryradiationoccupationsDto.setDatefromto(dimeInquiryradiationoccupation.getDatefromto());
                reportInquiryradiationoccupationsDto.setCompany(dimeInquiryradiationoccupation.getCompany());
                reportInquiryradiationoccupationsDto.setWorkshop(dimeInquiryradiationoccupation.getWorkshop());
                reportInquiryradiationoccupationsDto.setOccupationexposure(dimeInquiryradiationoccupation.getOccupationexposure());
                reportInquiryradiationoccupationsDto.setOccupationtype(dimeInquiryradiationoccupation.getOccupationtype());
                reportInquiryradiationoccupationsDto.setRadiationcategory(dimeInquiryradiationoccupation.getRadiationcategory());
                reportInquiryradiationoccupationsDto.setWorkhours(dimeInquiryradiationoccupation.getWorkhours());
                reportInquiryradiationoccupationsDto.setExposuretotal(dimeInquiryradiationoccupation.getExposuretotal());
                reportInquiryradiationoccupationsDto.setExposureexcess(dimeInquiryradiationoccupation.getExposureexcess());
                if (dimeInquiryitems != null) {
                    reportInquiryradiationoccupationsDto.setRemark(dimeInquiryitems.getRemark());
                }
                reportInquiryradiationoccupationsDto.setPhysicalRegisterId(dimePhysicalregister.getId());

                reportInquiryradiationoccupationsDtos.add(reportInquiryradiationoccupationsDto);
            }
        }
        personReportDto.setV_print_inquiryradiationoccupations(reportInquiryradiationoccupationsDtos);

        DimeInquiryradiationother inquiryradiationother = dimeInquiryradiationotherMapper.selectDimeInquiryradiationotherByPhysicalId(dimePhysicalregister.getId());

        List<ReportInquiryradiationotherDto> reportInquiryradiationotherDtos = new ArrayList<>();
        if (inquiryradiationother != null) {

            ReportInquiryradiationotherDto reportInquiryradiationotherDto = new ReportInquiryradiationotherDto();
            reportInquiryradiationotherDto.setCheckCode(dimePhysicalregister.getCheckCode());
            reportInquiryradiationotherDto.setDoctorId(inquiryradiationother.getDoctorId());
            reportInquiryradiationotherDto.setDoctorName(inquiryradiationother.getDoctorName());
            reportInquiryradiationotherDto.setSpouseradiation(inquiryradiationother.getSpouseradiation());
            reportInquiryradiationotherDto.setSpousehealth(inquiryradiationother.getSpousehealth());
            reportInquiryradiationotherDto.setTrainingorg(inquiryradiationother.getTrainingorg());
            reportInquiryradiationotherDto.setMarriagedate(inquiryradiationother.getMarriagedate());
            reportInquiryradiationotherDto.setEducation(inquiryradiationother.getEducation());
            reportInquiryradiationotherDto.setRemark(inquiryradiationother.getRemark());
            reportInquiryradiationotherDto.setPhysicalRegisterId(dimePhysicalregister.getId());
            reportInquiryradiationotherDtos.add(reportInquiryradiationotherDto);
        }
        personReportDto.setV_print_inquiryradiationother(reportInquiryradiationotherDtos);


        DimeInquirysign dimeInquirysign = dimeInquirysignMapper.selectDimeInquirysignByPhysicalId(dimePhysicalregister.getId());

        List<ReportInquirysignDto> reportInquirysignDtos = new ArrayList<>();
        if (dimeInquirysign != null) {
            ReportInquirysignDto reportInquirysignDto = new ReportInquirysignDto();
            reportInquirysignDto.setCheckCode(dimePhysicalregister.getCheckCode());
            reportInquirysignDto.setPhysicalRegisterId(dimeInquirysign.getPhysicalRegisterId());
            reportInquirysignDto.setSignsoure(dimeInquirysign.getSignsoure());
            reportInquirysignDtos.add(reportInquirysignDto);

        }
        personReportDto.setV_print_inquirysign(reportInquirysignDtos);

        List<DimeInquirysymptom> dimeInquirysymptomList = dimeInquirysymptomMapper.selectDimeInquirysymptomByPhysicalId(dimePhysicalregister.getId());
        List<ReportInquirysymptomDto> reportInquirysymptomDtos = new ArrayList<>();
        if (dimeInquirysymptomList != null && dimeInquirysymptomList.size() > 0) {

            for (DimeInquirysymptom dimeInquirysymptom : dimeInquirysymptomList) {
                ReportInquirysymptomDto reportInquirysymptomDto = new ReportInquirysymptomDto();
                reportInquirysymptomDto.setCheckCode(dimePhysicalregister.getCheckCode());
                reportInquirysymptomDto.setPhysicalRegisterId(dimeInquirysymptom.getPhysicalRegisterId());
                reportInquirysymptomDto.setDoctorName(dimeInquirysymptom.getDoctorName());
                reportInquirysymptomDto.setDoctorSign("");
            }

        }
        personReportDto.setV_print_inquirysymptom(reportInquirysymptomDtos);


        return personReportDto;
    }

    @Override
    public PhysicalabnormalOrderDto getPhysicalOccDiseaseOrContraindications(SearchPhysicalregister dimePhysicalregister) {

        PhysicalabnormalOrderDto physicalabnormalOrderDto = new PhysicalabnormalOrderDto();
        List<ReportBasicInfo> dimePhysicalregisters = new ArrayList<>();

        ReportBasicInfo reportBasicInfo = ReportMappingPhysical(dimePhysicalregister);

        SysDictData searchdicdata = new SysDictData();
        searchdicdata.setDictType("dime_physical_work");
        searchdicdata.setDictValue(reportBasicInfo.getWorkStatus());

        R<SysDictData> Rdic = remoteDictService.getDictTypeName(searchdicdata);
        if (Rdic.getCode() != R.FAIL) {
            SysDictData dictData = Rdic.getData();
            reportBasicInfo.setWorkStatusName(dictData.getDictLabel());
        }

        dimePhysicalregisters.add(reportBasicInfo);

        physicalabnormalOrderDto.setDimePhysicalregisterList(dimePhysicalregisters);

        DimeMaincheckconclusion dimeMaincheckconclusion = dimeMaincheckconclusionMapper.selectDimeMaincheckconclusionByPhysicalId(dimePhysicalregister.getId());
        if (dimeMaincheckconclusion != null) {
            physicalabnormalOrderDto.dimeMaincheckconclusionList = new ArrayList<>();
            physicalabnormalOrderDto.dimeMaincheckconclusionList.add(dimeMaincheckconclusion);
        }


        List<DimeMaincheckharmconclusion> dimeMaincheckharmconclusionList = dimeMaincheckharmconclusionMapper.selectDimeMaincheckharmconclusionByPhysicalId(dimePhysicalregister.getId());
        if (Objects.equals(dimePhysicalregister.reportType, "OccDisease")) {
            List<DimeMaincheckharmconclusion> maincheckharmconclusionList = dimeMaincheckharmconclusionList.stream().filter(x -> Objects.equals(x.getOccupationalTag(), "1")).collect(Collectors.toList());
            physicalabnormalOrderDto.setDimeMaincheckharmconclusionList(maincheckharmconclusionList);
            List<DimeMaincheckharmoccupationaldiseae> dimeMaincheckharmoccupationaldiseaeList = dimeMaincheckharmoccupationaldiseaeMapper.selectDimeMaincheckharmoccupationaldiseaeByPhysicalId(dimePhysicalregister.getId());
            physicalabnormalOrderDto.setDimeMaincheckharmoccupationaldiseaeList(dimeMaincheckharmoccupationaldiseaeList);

        } else if (Objects.equals(dimePhysicalregister.reportType, "Contraindications")) {
            List<DimeMaincheckharmconclusion> maincheckharmconclusionList = dimeMaincheckharmconclusionList.stream().filter(x -> Objects.equals(x.getContraindicationTag(), "1")).collect(Collectors.toList());
            physicalabnormalOrderDto.setDimeMaincheckharmconclusionList(maincheckharmconclusionList);
            List<DimeMaincheckharmcontraindication> dimeMaincheckharmcontraindicationList = dimeMaincheckharmcontraindicationMapper.selectDimeMaincheckharmcontraindicationByPhysicalId(dimePhysicalregister.getId());
            physicalabnormalOrderDto.setDimeMaincheckharmcontraindicationList(dimeMaincheckharmcontraindicationList);

        } else if (Objects.equals(dimePhysicalregister.reportType, "RecheckCombs")) {
            List<DimeMaincheckharmconclusion> maincheckharmconclusionList = dimeMaincheckharmconclusionList.stream().filter(x -> Objects.equals(x.getRecheckTag(), "1")).collect(Collectors.toList());
            if (maincheckharmconclusionList.size() > 0) {
                physicalabnormalOrderDto.setDimeMaincheckharmconclusionList(maincheckharmconclusionList);
            }
            List<DimeMaincheckharmrecheckcomb> dimeMaincheckharmrecheckcombList = dimeMaincheckharmrecheckcombMapper.selectDimeMaincheckharmrecheckcombByPhysicalId(dimePhysicalregister.getId());
            if (dimeMaincheckharmrecheckcombList.size() > 0) {
                physicalabnormalOrderDto.setDimeMaincheckharmrecheckcombList(dimeMaincheckharmrecheckcombList);
            }
        }
        return physicalabnormalOrderDto;
    }

    @Override
    public List<DimePhysicalregister>  getPrintReportByTypeList(SearchPhysicalregister searchPhysicalregister) {

        List<DimePhysicalregister> dimePhysicalregisterList = new ArrayList<>();
        if (searchPhysicalregister != null && Objects.equals(searchPhysicalregister.reportType, "OccDisease")) {
            dimePhysicalregisterList = dimePhysicalregisterMapper.SearchRegisterOccDiseaselist(searchPhysicalregister);
        }
       else if (searchPhysicalregister != null && Objects.equals(searchPhysicalregister.reportType, "Contraindications")) {
            dimePhysicalregisterList = dimePhysicalregisterMapper.SearchRegisterContraindicationslist(searchPhysicalregister);
        }
        else if (searchPhysicalregister != null && Objects.equals(searchPhysicalregister.reportType, "RecheckCombs")) {
            dimePhysicalregisterList = dimePhysicalregisterMapper.SearchRegisterRecheckCombslist(searchPhysicalregister);
        }



        return dimePhysicalregisterList;
    }



    private PhysicalReportDto MappingPhysical(DimePhysicalregister physicalregister) {
        PhysicalReportDto physicalReportDto = new PhysicalReportDto();
        physicalReportDto.setId(physicalregister.getId());
        physicalReportDto.setAge(physicalregister.getAge());
        physicalReportDto.setAddress(physicalregister.getAddress());
        physicalReportDto.setBirthday(physicalregister.getBirthday());
        physicalReportDto.setBaseCompanyId(physicalregister.getBaseCompanyId());
        physicalReportDto.setBasePackageId(physicalregister.getBasePackageId());
        physicalReportDto.setChannel(physicalregister.getChannel());
        physicalReportDto.setCheckCode(physicalregister.getCheckCode());
        physicalReportDto.setCheckType(physicalregister.getCheckType());
        physicalReportDto.setCheckDate(physicalregister.getCheckDate());
        physicalReportDto.setCompanyName(physicalregister.getCompanyName());
        physicalReportDto.setCompletStatus(physicalregister.getCompletStatus());
        physicalReportDto.setEmpNo(physicalregister.getEmpNo());
        physicalReportDto.setIdNo(physicalregister.getIdNo());
        physicalReportDto.setIdNoType(physicalregister.getIdNoType());
        physicalReportDto.setJobType(physicalregister.getJobType());
        physicalReportDto.setDept(physicalregister.getDept());
        physicalReportDto.setLastCheckCode(physicalregister.getLastCheckCode());
        physicalReportDto.setMainConclusion(physicalregister.getMainConclusion());
        physicalReportDto.setPhone(physicalregister.getPhone());
        physicalReportDto.setHarmfacter(physicalregister.getHarmfacter());
        physicalReportDto.setName(physicalregister.getName());
        physicalReportDto.setCombLack(physicalregister.getCombLack());
        physicalReportDto.setMarriage(physicalregister.getMarriage());
        physicalReportDto.setPersonType(physicalregister.getPersonType());
        physicalReportDto.setWorkYears(physicalregister.getWorkYears());
        physicalReportDto.setWorkStatus(physicalregister.getWorkStatus());
        physicalReportDto.setWorkMonths(physicalregister.getWorkMonths());
        physicalReportDto.setTouchYears(physicalregister.getTouchYears());
        physicalReportDto.setTouchMonths(physicalregister.getTouchMonths());
        physicalReportDto.setTouchHarms(physicalregister.getTouchHarms());
        physicalReportDto.setSocialCode(physicalregister.getSocialCode());
        physicalReportDto.setShopCode(physicalregister.getShopCode());
        physicalReportDto.setSex(physicalregister.getSex());
        physicalReportDto.setSoaOrderNo(physicalregister.getSoaOrderNo());
        physicalReportDto.setServiceUid(physicalregister.getServiceUid());
        physicalReportDto.setRegisterDate(physicalregister.getRegisterDate());
        physicalReportDto.setReCheckTag(physicalregister.getReCheckTag());
        physicalReportDto.setPackageName(physicalregister.getPackageName());
        physicalReportDto.setPersonType(physicalregister.getPersonType());
        physicalReportDto.setHeadpicture(physicalregister.getHeadpicture());

        return physicalReportDto;

    }


    private ReportBasicInfo ReportMappingPhysical(DimePhysicalregister physicalregister) {
        ReportBasicInfo reportBasicInfo = new ReportBasicInfo();
        reportBasicInfo.setHeadUrl(physicalregister.getHeadUrl());
        reportBasicInfo.setHeadpicture(physicalregister.getHeadpicture());

        reportBasicInfo.setNation(physicalregister.getNation());
        reportBasicInfo.setId(physicalregister.getId());
        reportBasicInfo.setCheckCode(physicalregister.getCheckCode());
        reportBasicInfo.setIdNo(physicalregister.getIdNo());
        reportBasicInfo.setName(physicalregister.getName());
        reportBasicInfo.setPersonType(physicalregister.getPersonType());
        reportBasicInfo.setCheckType(physicalregister.getCheckType());
        reportBasicInfo.setIdNoType(physicalregister.getIdNoType());
        reportBasicInfo.setSex(physicalregister.getSex());
        reportBasicInfo.setAge(physicalregister.getAge());
        reportBasicInfo.setMarriage(physicalregister.getMarriage());
        reportBasicInfo.setPhone(physicalregister.getPhone());
        reportBasicInfo.setAddress(physicalregister.getAddress());
        reportBasicInfo.setBirthday(physicalregister.getBirthday());
        reportBasicInfo.setBasePackageId(physicalregister.getBasePackageId());
        reportBasicInfo.setPackageName(physicalregister.getPackageName());
        reportBasicInfo.setBaseCompanyId(physicalregister.getBaseCompanyId());
        reportBasicInfo.setCompanyName(physicalregister.getCompanyName());
        reportBasicInfo.setRegisterDate(physicalregister.getRegisterDate());
        reportBasicInfo.setCheckDate(physicalregister.getCheckDate());
        reportBasicInfo.setChannel(physicalregister.getChannel());
        reportBasicInfo.setReportPrintDate(physicalregister.getReportPrintDate());
        reportBasicInfo.setMainCheckDate(physicalregister.getMainCheckDate());
        reportBasicInfo.setReportPrinter(physicalregister.getReportPrinter());
        reportBasicInfo.setJobType(physicalregister.getJobType());
        reportBasicInfo.setEmpNo(physicalregister.getEmpNo());
        reportBasicInfo.setDept(physicalregister.getDept());
        reportBasicInfo.setWorkStatus(physicalregister.getWorkStatus());
        reportBasicInfo.setCompletStatus(physicalregister.getCompletStatus());
        reportBasicInfo.setHarmfacter(physicalregister.getHarmfacter());
        reportBasicInfo.setPassword(physicalregister.getPassword());
        reportBasicInfo.setWorkYears(physicalregister.getWorkYears());
        reportBasicInfo.setWorkMonths(physicalregister.getWorkMonths());
        reportBasicInfo.setTouchYears(physicalregister.getTouchYears());
        reportBasicInfo.setTouchMonths(physicalregister.getTouchMonths());
        reportBasicInfo.setNeedAsk(physicalregister.getNeedAsk());
        reportBasicInfo.setReCheckTag(physicalregister.getReCheckTag());
        reportBasicInfo.setLastCheckCode(physicalregister.getLastCheckCode());
        reportBasicInfo.setCombLack(physicalregister.getCombLack());
        reportBasicInfo.setSocialCode(physicalregister.getSocialCode());
        reportBasicInfo.setServiceUid(physicalregister.getServiceUid());
        reportBasicInfo.setSoaOrderNo(physicalregister.getSoaOrderNo());
        reportBasicInfo.setPlatformTag(physicalregister.getPlatformTag());
        reportBasicInfo.setCheckResult(physicalregister.getCheckResult());
        reportBasicInfo.setMainConclusion(physicalregister.getMainConclusion());
        reportBasicInfo.setHealthSuggestion(physicalregister.getHealthSuggestion());
        reportBasicInfo.setMainCheckDoctor(physicalregister.getMainCheckDoctor());
        reportBasicInfo.setTakeReportType(physicalregister.getTakeReportType());
        reportBasicInfo.setIsValid(physicalregister.getIsValid());
        reportBasicInfo.setShopCode(physicalregister.getShopCode());
        reportBasicInfo.setTouchHarms(physicalregister.getTouchHarms());
        reportBasicInfo.setNationality(physicalregister.getNationality());
        reportBasicInfo.setRegistertype(physicalregister.getRegistertype());
        reportBasicInfo.setSearchValue(physicalregister.getSearchValue());
        reportBasicInfo.setCreateBy(physicalregister.getCreateBy());
        reportBasicInfo.setCreateTime(physicalregister.getCreateTime());
        reportBasicInfo.setUpdateBy(physicalregister.getUpdateBy());
        reportBasicInfo.setUpdateTime(physicalregister.getUpdateTime());
        reportBasicInfo.setRemark(physicalregister.getRemark());
        reportBasicInfo.setParams(physicalregister.getParams());
        return reportBasicInfo;

    }

}
